package com.baidu.foodrecipe.ui.bindingEvents

import android.view.View
import android.widget.ImageView
import androidx.navigation.NavDirections
import androidx.navigation.findNavController
import androidx.navigation.fragment.FragmentNavigatorExtras
import com.baidu.foodrecipe.R
import com.baidu.foodrecipe.data.model.Result
import com.baidu.foodrecipe.ui.fragment.favorite.FavoriteHomeFragmentDirections
import com.baidu.foodrecipe.ui.fragment.recipes.RecipesFragmentDirections
import kotlinx.parcelize.Parcelize

class ClickEvents {
    //点击主页进入详情页的事件
    fun showDetails(view: View, item: Result, isFavoritePage: Boolean = true) {
        var direction = if (isFavoritePage) {//收藏
            //创建Direction对象 配置传递的参数
            FavoriteHomeFragmentDirections.actionFavoriteHomeFragmentToDetailsFragment2(item)
        } else {//主页
            //创建Direction对象 配置传递的参数
            RecipesFragmentDirections.actionRecipesFragmentToDetailsFragment(item)
        }

        //获取view的子view 食谱的图片视图
        //传递的view是item布局容器视图
        val recipeImage = view.findViewById<ImageView>(R.id.image)
        //创建共享动画对象
        val extras = FragmentNavigatorExtras(Pair(recipeImage, "recipe_animation_image"))

        view.findNavController().navigate(direction, extras)
    }
}